package com.songtao.rabbitmq.util;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.songtao.rabbitmq.config.RabbitConfig;

public class RabbitConnectionUtils {
        

    
    /**
     * 获取rabbitmq链接
     * @throws TimeoutException 
     * @throws IOException 
     */
    public static Connection getConnection() throws IOException, TimeoutException{
        ConnectionFactory factory = new ConnectionFactory();
        
        factory.setHost(RabbitConfig.IP_ADDRESS);
        factory.setPort(RabbitConfig.PORT);
        factory.setVirtualHost(RabbitConfig.VHOST);
        factory.setUsername(RabbitConfig.USERNAME);
        factory.setPassword(RabbitConfig.PASSWORD);
        
        return factory.newConnection();
    }
}
